<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width:220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <img>
        <UploadImg @input="asdas"
            :value="userInfo.staffPhoto||''"
            ></UploadImg>//val =>//userInfo.staffPhoto=val
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="hSui">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { headPortraits } from "@/api/user";
import { Departments } from "@/api/departments";
export default {
    
  data() {
    return {
      
      userId: this.$route.query.id,
      userInfo: {
        mobile: '',
        timeOfEntry: '',
        
      }
    }
  },
  created(){
    this.loadPortraits()
  },
  methods:{
    asdas(al){
      this.userInfo.staffPhoto=al
      console.log(this.userInfo.staffPhoto);
    },
    // 获取信息
    async loadPortraits() {
      try {
        const res = await headPortraits(this.userId);
        console.log(res);
        this.userInfo = res.data;
        this.$store.commit('user/userInf',this.userInfo)
        
      } catch (error) {
        console.log(error);
      }
    },
    // 保存信息
    async hSui(){
         try {
           const res= await Departments(this.userInfo)
           console.log(res);
            this.loadPortraits()
            this.$router.back()
           
        } catch (error) {
           console.log(error); 
        }
    }
  }
}
</script>

<style scoped lang="scss">
  .user-info{
    padding-top:20px;
  }
</style>